/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package riteservices.services;

import java.util.List;
import java.util.Vector;
import riteservices.model.bean.Notification;
import riteservices.model.bean.User;
import riteservices.model.dao.NotificationDAO;

/**
 *
 * @author denis
 */
public class NotificationSrv {

    NotificationDAO notificationDao = new NotificationDAO();

    public void sendNotificationToUser(int userid,Notification notification){
    notificationDao.saveNotificationToUser(userid, notification);
    }

    public void sendNotificationForPassangers(int roundid, Notification notification, Vector<User> passanger){
    notificationDao.saveForMultiplesPassangers(roundid, notification, passanger);
    }

    public List<Notification> getPendingNotification(int userid){
        return notificationDao.getPendingNotifications(userid);

    }

    public List<Notification> loadNotReadedNotification(int userid){
    return notificationDao.getPendingNotifications(userid);
    }

    public void deleteAllNotifiaction(int userid){

       List<Notification> notifications= notificationDao.search("User_idUser="+userid+" and status=1",Notification.class);
       for(int indice=0;indice<notifications.size();indice++){
       Notification notification=new Notification();
       notification.setIdNotification(notifications.get(indice).getIdNotification());
       notificationDao.delete(notification);
       }
    }

    public void deleteNotification(int notificationid){
//        Notification notification=new Notification();
//        notification.setIdNotification(notificationid);
        notificationDao.delete(this.getById(notificationid));
    }
    
    public void update(Notification notification){
        notificationDao.update(notification);
    }
    
    public Notification getById(int id){
        return notificationDao.getById(id);
    }

}
